//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { Image as VanImage } from "vant";
import { scrollMixin } from "utils/mixin";
export default {
  mixins: [scrollMixin], //加载更多
  name:'',
  //import引入的组件需要注入到对象中才能使用
  components: {
    VanImage
  },
  data() {
  return {
    active:0,
    incomeName:'',
    point:'',
    usableLove:'',
    frozeLove:'',
    isLoadMore: true,
    page: 1,
    totalPage: 0,
    rewardStatus:false,
    rewardName:'提成状态',
    balanceName:'结算类型',
    rewardType:false,
    rewardsArr:[
      {
        name:'管理提成',
        status:1
      },
      {
        name:'培育奖',
        status:2
      },
      {
        name:'额外奖励',
        status:3
      }
    ],
    query: {
      awardType:1,
      settledStatus:0,
      settledType:0,
      page:1
    },
    deductList:[
      {
        name:'提成状态',
        status:0
      },
      {
        name:'未结算',
        status:1
      },
      {
        name:'已结算',
        status:2
      },
      {
        name:'已失效',
        status:-1
      }
    ],
    rewardArr:[
      {
        name:'结算类型',
        status:0
      },
      {
        name:'收入',
        status:1
      },
      {
        name:'积分',
        status:2
      },
      {
        name:'可用爱心值',
        status:3
      },
      {
        name:'冻结爱心值',
        status:4
      }
    ],
    setting:{},
    statistic:{
		},
    member:{},
    rewardsList:[]
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    royaltiesOn() {
      this.rewardStatus = !this.rewardStatus;
      this.rewardType = false;
    },
    royaltiesTypeOn() {
      this.rewardType = !this.rewardType;
      this.rewardStatus = false;
    },
    directlyOn() {
      this.$router.push(this.fun.getUrl("projectDirectly", {}, {}));
    },
    rewardsTab(status) {
      this.query.awardType = status;
      this.query.page = 1;
      this.teamIndex();
      this.recordsList();
    },
    initData() {
      this.active = 0;
      this.isLoadMore= true;
      this.query.awardType = 1;
      this.query.settledStatus = 0;
      this.query.settledType = 0;
      this.query.page = 1;
    },
    deductOn(item,type) {
      this.rewardStatus = false;
      this.rewardType = false;
      this.query[type] = item.status;
      if(type === 'settledStatus') {
        this.rewardName = item.name;
      } else {
        this.balanceName = item.name;
      }
      this.query.page = 1;
      this.recordsList();
    },
    teamIndex() {
      let json = {
        basic_info:1,
        award_type:this.query.awardType
      };
      $http.post("plugin.manager-team.frontend.controllers.page.index", json, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            let basic_info = response.basic_info;
            const {member,setting,statistic} = {...res};
            this.member = member;
            this.setting = setting;
            this.statistic = statistic;
            this.point = basic_info.lang.member_center.credit1 || '积分'; //积分
            this.usableLove = basic_info.plugin_setting.love?.usable_love_name;
            this.frozeLove = basic_info.plugin_setting.love?.froze_love_name;
            this.rewardArr[1].name = basic_info.lang.income?.income_name;
            this.rewardArr[2].name = this.point;
            this.rewardArr[3].name = this.usableLove;
            this.rewardArr[4].name = this.frozeLove;
            this.fun.setWXTitle(`${res.manager_team_name}`);
          } else {
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    recordsList() {
      let json = {
        award_type:this.query.awardType,
        settled_status: this.query.settledStatus,
        settled_type: this.query.settledType,
        page:this.query.page
      };
      $http.post("plugin.manager-team.frontend.modules.income.controllers.records.index", json, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data.page_list;
            this.isLoadMore = true;
            this.totalPage = res.last_page;
            if (!this.totalPage) {
              this.query.page = 0;
            }
            this.rewardsList = res.data;

          } else {
            this.query.page = this.query.page - 1;
            this.isLoadMore = false;
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    //获取更多数据
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.query.page >= this.totalPage) {
        return;
      } else {
        this.query.page = this.query.page + 1;
        let json = {
          award_type:this.query.awardType,
          settled_status: this.query.settledStatus,
          settled_type: this.query.settledType,
          page:this.query.page
        };
        $http.post("plugin.manager-team.frontend.modules.income.controllers.records.index", json, "加载中").then(
          res => {
            this.isLoadMore = true;

            if (res.result === 1) {
              let myData = res.data.page_list.data;
              this.rewardsList = [...this.rewardsList, ...myData]; //数组拼接
            } else {
              this.query.page = this.query.page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            // error callback
          }
        );
      }
    },
    // 自定义提现收入语言
    customizeIncome() {
      let mailLanguage = this.fun.initMailLanguage();
      //自定义收入字段
      this.incomeName = mailLanguage.income.income_name;
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
  
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    // this.fun.setWXTitle(this.fun.initWithdrawal());
    this.initData();
    this.teamIndex();
    this.customizeIncome();
    this.recordsList();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
  }